﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Arkanoid
{
    class Pallete : Object 
    {
        public int Life = 3;

        public Pallete(GameWindow janela, Texture2D texture, Vector2 position)
            :base(janela, texture, position) 
        {
            this.position = position;
            this.velocity = new Vector2(5, 0);
            this.size = texture.Bounds;   
        }

        public override void Update(){}

        public void Update(GameWindow janela, GameTime gametime, List<Keys> teclas) 
        {
            this.size.X = (int)position.X;
            this.size.Y = (int)position.Y;

            foreach (Keys tecla in teclas)
            {
                if (Keyboard.GetState().IsKeyDown(tecla) && tecla == Keys.Right)
                {
                    if (position.X > (janela.ClientBounds.Width - this.texture.Width) - 10)
                    {
                        position.X = (janela.ClientBounds.Width - this.texture.Width) - 10;
                    }
                    position += velocity;
                }

                if (Keyboard.GetState().IsKeyDown(tecla) && tecla == Keys.Left)
                {
                    if (position.X < 10)
                    {
                        position.X = 10;
                    }
                    position -= velocity;
                }
            } 
 
        }

        public BoundingBox GetBounding()
        {
            return new BoundingBox(new Vector3(this.position.X, this.position.Y, 0.0f),
                new Vector3(this.position.X + this.size.Width, this.position.Y + this.size.Height, 0.0f));
        }

        //Desenha a pallete na tela
        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, Color.White);
        }

    }
}
